package com.canbot.u05.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.canbot.u05.R;
import com.canbot.u05.activity.admin.AdminFaceChooseActivity;
import com.canbot.u05.bean.PersonGroupData;

import java.util.List;

public class AdminFaceGroupAdapter extends RecyclerView.Adapter<AdminFaceGroupAdapter.MyViewHolder> {

    private static final String TAG = "AdminFaceGroupAdapter";
    private Context mContext;
    private List<PersonGroupData> groupList;
    private OnItemClickListener listener;

    public AdminFaceGroupAdapter(Context context, List<PersonGroupData> groupList) {
        this.groupList = groupList;
        this.mContext = context;
    }

    public void setGroupList(List<PersonGroupData> groupList){
        this.groupList = groupList;
        notifyDataSetChanged();
    }

    public void setItemClickListener(OnItemClickListener listener){

        this.listener = listener;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_admin_face_group, viewGroup,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int position) {
        myViewHolder.groupName.setText(groupList.get(position).getName());
        myViewHolder.groupContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (listener != null){
                    listener.onItemClick(groupList.get(position).getId());
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return groupList.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        private TextView groupName;
        private RelativeLayout groupContainer;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            groupName = itemView.findViewById(R.id.tv_face_group_name);
            groupContainer = itemView.findViewById(R.id.rl_face_group_container);
        }
    }

    public interface OnItemClickListener{
        void onItemClick(int groupId);
    }
}
